#region

using System;
using System.IO;
using System.Windows.Forms;

#endregion

namespace MediaController.Extractor
{
    internal class DragDropSupport
    {
        
        #region Delegates

        public delegate void DropHandler(DirectoryInfo dir);

        #endregion

        public DragDropSupport(Control c, DropHandler handler)
        {
            c.DragEnter += DragEnter;
            c.DragDrop += DragDrop;
            Drop = (DropHandler) Delegate.Combine(Drop, handler);
        }

        public event DropHandler Drop;

        public void DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.SymbolicLink))
            {
                var data = (string[]) e.Data.GetData(DataFormats.FileDrop);
            }
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                var strArray = (string[]) e.Data.GetData(DataFormats.FileDrop);
                Drop(new DirectoryInfo(strArray[0]));
            }
        }

        public void DragEnter(object sender, DragEventArgs e)
        {
            bool flag = false;
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                var data = (string[]) e.Data.GetData(DataFormats.FileDrop);
                if (data.Length >= 1)
                {
                    var info = new DirectoryInfo(data[0]);
                    if (info.Exists)
                    {
                        flag = true;
                    }
                }
            }
            if (flag)
            {
                e.Effect = DragDropEffects.Move | DragDropEffects.Copy | DragDropEffects.Scroll;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }

        // Nested Types
    }
}